package adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.lidroid.xutils.DbUtils;

import java.util.ArrayList;
import java.util.List;

import custom.ShoppingItem;
import utils.ShoppingCart;

/**
 * Created by Mr.xingkong on 2016/1/18.
 */
public class ShoppingSortLvAdapter extends BaseAdapter
{
    List<List<ShoppingCart>> data;
    Context context;
    public ShoppingSortLvAdapter(Context context)
    {
        data = new ArrayList<>();
        this.context = context;
    }

    public void setData( List<List<ShoppingCart>> data)
    {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder vh;
        if (convertView == null)
        {
            convertView = new ShoppingItem(context);
            vh = new ViewHolder();
            vh.shoppingItem = (ShoppingItem) convertView;

            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }

        vh.shoppingItem.setData(data.get(position));
        return convertView;
    }

    class ViewHolder
    {
        ShoppingItem shoppingItem;
    }
}
